home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 21 / CU Amiga Magazine's Super CD-ROM 21 (1998)(EMAP Images)(GB)[!][issue 1998-04].iso / CUCD / Utilities / PGP / source / pgp50i-b8a / tools / mempool.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-01-04  |  1.0 KB  |  35 lines

  1. #ifndef MEMPOOL_H
  2. #define MEMPOOL_H
  3.  
  4. typedef struct MemPool {
  5.     struct PoolBuf *head;
  6.     char *freeptr;
  7.     unsigned freespace;
  8.     unsigned chunksize;    /* Default starting point */
  9.     unsigned long totalsize;
  10.     int (*purge)(void *);    /* Return non-zero to retry alloc */
  11.     void *purgearg;
  12. } MemPool;
  13.  
  14. /* A global pool for miscellaneous stuff. */
  15. extern struct MemPool MiscPool;
  16.  
  17. /*
  18.  * Nice clean interfaces
  19.  */
  20. void memPoolInit(struct MemPool *pool);
  21. void memPoolSetPurge(struct MemPool *pool, int (*purge)(void *), void *arg);
  22. void memPoolEmpty(struct MemPool *pool);
  23. void memPoolCutBack(struct MemPool *dest, struct MemPool const *cutback);
  24. void *memPoolAlloc(struct MemPool *pool, unsigned len, unsigned alignment);
  25. #ifdef DEADCODE
  26. char const *memPoolStore(struct MemPool *pool, char const *str);
  27. #endif
  28.  
  29. /* Lookie here!  An ASNI-compliant alignment finder! */
  30. #define alignof(type) (sizeof(struct{type _x; char _y;}) - sizeof(type))
  31.  
  32. #define memPoolNew(pool, type) memPoolAlloc(pool, sizeof(type), alignof(type))
  33.  
  34. #endif /* MEMPOOL_H */
  35.